package cn.paxos.mysql.config;

import cn.paxos.mysql.MySqlListener;
import cn.paxos.mysql.engine.SqlEngine;
import cn.paxos.mysql.h2enginee.H2SqlEngineeImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * h2databasesql引擎配置
 */
@Configuration
public class SqlEngineeConfiguration {

    /**
     * 启动的sql引擎
     * @return
     */
    @Bean
    public SqlEngine sqlEngine() {
        SqlEngine sqlEngine = new H2SqlEngineeImpl();
        return sqlEngine;
    }

    /**
     * 启动sql
     * @return
     */
    @Bean
    public MySqlListener sqlListener(@Autowired  SqlEngineeProperty sqlEngineeProperty) {
        MySqlListener enginee = new MySqlListener(sqlEngineeProperty.getPort(), sqlEngineeProperty.getExecutors(), sqlEngine());
        return enginee;
    }
}
